#ifndef CLOCK_TIMER_HPP
#define CLOCK_TIMER_HPP

#include <cpp3ds/Graphics/Drawable.hpp>
#include <cpp3ds/Graphics/Text.hpp>
#include <cpp3ds/Window/Event.hpp>
#include <cpp3ds/System/Clock.hpp>
#include <cpp3ds/Audio/Sound.hpp>
#include "TweenObjects.hpp"
#include "Chronometer.hpp"
#include "States/State.hpp"
#include "GUI/ScrollBar.hpp"
#include <TweenEngine/Tween.h>
#include <TweenEngine/TweenManager.h>
#ifndef EMULATION
#include <3ds.h>
#endif

namespace Clock {

class Timer : public cpp3ds::Drawable, public util3ds::TweenTransformable<cpp3ds::Transformable> {
public:
	void update(float delta);
	void processEvent(const cpp3ds::Event& event);

	Timer();
	~Timer();

	void play();
	void pause();
	void stop();
	void toggle();
	void reset();
	bool isRunning();
	cpp3ds::Time getElapsedTime();
	cpp3ds::Time getRemainingTime();

	void updateTimeTexts();

protected:
	virtual void draw(cpp3ds::RenderTarget& target, cpp3ds::RenderStates states) const;

	int getNumberFromUser(int defaultNumber);
	void updateUnit(int *unit);

	void resetNumbers();
	void addMinute();

private:
	util3ds::TweenText m_textTimerHours;
	util3ds::TweenText m_textTimerMinutes;
	util3ds::TweenText m_textTimerSeconds;

	util3ds::TweenText m_textHourTwoPoints;
	util3ds::TweenText m_textMinuteTwoPoints;

	util3ds::TweenCircleShape m_startButton;
	util3ds::TweenText m_textStart;
	bool m_stopButtonInteract;
	util3ds::TweenCircleShape m_stopButton;
	util3ds::TweenText m_textStop;

	util3ds::TweenText m_textAddMinute;
	util3ds::TweenText m_textResetTimer;

	sftools::Chronometer m_mainStopwatch;

	cpp3ds::Time m_timeLeft;
	int m_timeHour;
	int m_timeMinute;
	int m_timeSecond;
	bool m_requestAddMinute;

	cpp3ds::Sound m_soundTimerOver;

	TweenEngine::TweenManager m_tweenManager;

};

} // namespace Clock

#endif // CLOCK_TIMER_HPP
